package org.vox.homepage.util

import org.apache.commons.codec.digest.DigestUtils
import org.apache.commons.lang3.StringUtils

import scala.collection.SortedMap

/**
  * @author Borg.lee
  */
object CrytoUtils {
  /**
    * convert param map to SHA1 code
    * @param params
    * @param secret
    * @return
    */
  def makeSHA1Hash(params: SortedMap[String, Object], secret: String): String = {
    if (params == null || params.isEmpty) {
      throw new IllegalArgumentException("params must not be empty")
    }

    if (StringUtils.isBlank(secret)) {
      throw new IllegalArgumentException("secret must not be empty")
    }

    val source = params.map(x => x._1 + "=" + x._2).mkString("&")
    DigestUtils.sha1Hex(source + secret)
  }
}
